#ifndef __RTC_H__
#define __RTC_H__

#include "gd32f10x.h"
#include "stdio.h"

typedef struct
{
    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
} date_time_t;

void RTC_Config(void);

uint8_t RTC_Init(void);

int is_leap_year(int year);

int days_from_1970(int year, int month, int day);

void seconds_to_datetime(uint32_t epoch_seconds, uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *minute, uint8_t *second);

uint8_t RTC_Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); // 将设置时间转化为秒数，给到RTC_CNT寄存器

uint8_t RTC_Get(void); // 获取RTC_CNT寄存器的秒数，并转化为日期

extern date_time_t date_time;

#endif
